/*
 * Copyright (C) 2009 Chang Min Lee <ch5ngmn@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details. (/COPYING)
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#include "CliCommBroker.h"
#include "ace/Log_Msg.h"
#include "ace/ARGV.h"
#include "ace/Get_Opt.h"
#include "ace/Arg_Shifter.h"

CliCommBroker::CliCommBroker (const ACE_TCHAR *id, IoEventHandler *handler) 
:id_(id), proxy_manager_(0), handler_(handler)
{
	ACE_ASSERT(handler);
}

int
CliCommBroker::open (int argc, ACE_TCHAR *argv [])
{ 
	if (0 == CommBroker::open (argc, argv))
	{
		proxy_manager_.reset(new ProxyManager(id_.c_str(), handler_, orb_.in(), naming_.in()));
		
		return proxy_manager_->open();
	}
	return -1;
}

void 
CliCommBroker::send (const ACE_TCHAR * server_name, const ACE_UINT8 *data, ACE_UINT32 data_len)
{
	proxy_manager_->process (server_name, data, data_len);
}


void
CliCommBroker::close (bool wait_for_completion)
{
	proxy_manager_->close();
	CommBroker::close (wait_for_completion);
}